<template>
  <ArticleEditor
    title="新撰文章"
    :submitLoading="loading.state.value"
    @submit="fetchCreateArticle"
  ></ArticleEditor>
</template>
<script lang="ts" setup>
import { useRouter } from 'vue-router'

import ArticleEditor from './Editor/index.vue'
import { createArticle } from '@/store/article'
import type { Article } from '@/constants/article'
import { useLoading } from '@/handcer'
const loading = useLoading()

const router = useRouter()

const fetchCreateArticle = (article: Article) => {
  return loading.promise(createArticle(article)).then((result) => {
    router.push(`/article/edit/${result._id!}`)
    // scrollTo(document.body);
  })
}
</script>

<style lang="less" scoped></style>
